package com.itserver.controller.sysController;


import com.itserver.pojo.PageResult;
import com.itserver.pojo.Result;
import com.itserver.pojo.sys.QueryRole;
import com.itserver.pojo.sys.Role;
import com.itserver.service.sys.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("sys/role")
public class RoleController {
    @Autowired
    private RoleService roleService;

    // 角色列表
    @GetMapping
    public Result page(QueryRole queryRole) {
        PageResult<Role> pageResult = roleService.page(queryRole);
        return Result.success(pageResult);
    }
    // 新增角色
    @PostMapping
    public Result add(@RequestBody Role role) {
        roleService.add(role);
        return Result.success();
    }
    // 修改角色
    @PutMapping
    public Result update(@RequestBody Role role ) {
        roleService.update(role);
        return Result.success();
    }
    // 删除角色
    @DeleteMapping
    public Result delete(@RequestParam List<Integer> ids) {
        roleService.delete(ids);
        return Result.success();
    }
    //角色详情
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        Role role = roleService.getById(id);
        return Result.success(role);
    }

}
